<template>
  <div>
    <div>
      <el-input type="textarea" v-model="textarea" placehoder="输string" name="" />
      <el-button type="primary" size="small" @click="str2array"
        >数据整理成array</el-button
      >
      <el-button type="primary" size="small" @click="str2tablecolumn"
        >array生成 el-table-column</el-button
      >
      <el-button type="primary" size="small" @click="str2formitem"
        >array生成 el-form-item</el-button
      >
    </div>
    <pre>{{ list }}</pre>
    <hr />
    <pre>{{ resultstr }}</pre>
    <hr />
    <pre>{{ resultstr_formitem }}</pre>
    <hr />
    
  </div>
</template>

<script>
import { lodashMap } from "../../../utils/lodashUtil";
import { i } from '../../../../dist/assets/chunk-core-js.f11001bf';

export default {
  data() {
    return {
      textarea: "",
      list: [],
      resultstr: "",
      resultstr_formitem: "",
    };
  },
  methods: {
    /**
     * @desc
     * @params _data.tableId
     * @return
     */
    initByDialog(_data) {},
    str2array() {
      this.list = this.textarea
        ?.split(" ")
        .filter((i) => i)
        .map((i) => i.trim());
    },
    str2tablecolumn() {
      var str = "";
      lodashMap(this.list, (item) => {
        str += `<el-table-column
        min-width="120px"
        label="${item}"
        prop="${item}"
        align="center"
        >
        <template slot-scope="scope">
          <tip-content :value="scope.row.${item}" :overflow="1">{{scope.row.${item}}}</tip-content>
        </template>
      </el-table-column>`;
      });
      this.resultstr = str;
    },
    str2formitem() {
      var str = "";
    // 
      lodashMap(this.list, (item) => {
        str += `    <el-form-item desc="${item}" label="${item}" prop="${item}" disabled="false">
            <div slot="label"><!-- <i class="red" style="padding-right:2px;">*</i> --> ${item}</div>  
<div style="width: 120px;">
          <el-input v-model.trim="formData.${item}"
                    :disabled="false" placeholder="${item}" size="small"
                    style="width: 120px;"
                    clearable />
        </div>
      </el-form-item>`;
      });
      this.resultstr_formitem = str;
    },
    submitByDialog() {},
  },
};
</script>
